import axios from 'axios'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

// ES6 Promise的封装
export function request(config) {
    // 1.创建axios的实例对象
    const instance = axios.create({
        baseURL: '/api',
        timeout: 5000
    })

    instance.interceptors.request.use(res => {
        NProgress.start()
        return res
    })

    // 过滤器(拦截器)
    instance.interceptors.response.use(res => {
        NProgress.done()
        return res.data
    })

    // 通过实例发送网络请求
    return instance(config)
}